<?php
	@session_start();
	include("../../connect/connect_mysql.php");
	
	$act= $_POST["act"];
 	switch($act){
 		case 'image_collection':
 			$id= 3;	
 		break;
 		case 'image_event':
 			$id= 5;	
 		break;
		case 'image_banner':
			$id= 7;
 		break;
 		case 'image_menu':
			$id= 2;
 		break;
 		case 'image_header':
			$id= 8;
 		break;
 		case 'image_gallery':
			$id= 9;
 		break;
 		case 'image_onpress':
			$id= 10;
 		break;
 	}
function result_array($result)
{
    $table_result=array();
    $r=0;
    $str="";
    while($row = mysql_fetch_assoc($result)){
        $arr_row=array();
        $c=0;
        $str.= "{";
        while ($c < mysql_num_fields($result)) {       
            $col = mysql_fetch_field($result, $c);   
//            $arr_row[$col -> name] = $row[$col -> name];        
          	$str .= $row[$col -> name] . "#";   
            $c++;
        }
        $str = chop($str,"#");
        $str .= "}#";   
//        $table_result[$r] = $arr_row;
        $r++;
    }   
    $str= chop($str,"#");
	$str = str_replace(".-", "\n", $str);

    return $str;
}
 $eid = $_POST["event_id"];
 if ($eid == 0) {
 	$query = "SELECT * FROM image WHERE page_id = '$id' and is_deleted = '0' ORDER BY `index` ASC";
 	mysql_query ("SET NAMES 'utf8'");
 	$result = mysql_query($query) or die(mysql_error());
	if ($result){
		$arr_table_result= result_array($result);
		echo ($arr_table_result);
	}else{
		$str = "";
		echo $str;
	}
 }else{
 	$query = "SELECT * FROM image WHERE page_id = '$id' and event_id = '$eid' and is_deleted = '0' ORDER BY `index` ASC";
 	mysql_query ("SET NAMES 'utf8'");
 	$result = mysql_query($query) or die(mysql_error());
	if ($result){
		$arr_table_result= result_array($result);
		echo ($arr_table_result);
	}else{
		$str = "";
		echo $str;
	} 	
 }
?>
	